<template>
  <a-form :labelCol="{ span: 3 }">
    <a-form-item label="抖音开始爬取：">
      <a-date-picker v-model:value="douyintime" placeholder="请选择抖音开始爬取时间" style="width: 100%" showTime />
    </a-form-item>
    <a-form-item label="小红书开始爬取：">
      <a-date-picker v-model:value="xiaohongshutime" placeholder="请选择小红书开始爬取时间" style="width: 100%" showTime />
    </a-form-item>
    <a-form-item label="淘宝开始爬取：">
      <a-date-picker v-model:value="taobaotime" placeholder="请选择淘宝开始爬取时间" style="width: 100%" showTime />
    </a-form-item>
  </a-form>
</template>

<script>
  import { ref, onMounted } from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import { useMessage } from '/@/hooks/web/useMessage';

  export default {
    name: 'CrawlerSettings',
    props: {
      // 行数据
      row: {
        type: Object,
        default: () => {},
        required: false,
      },
      // 该地址是online默认的编辑提交地址 如不满足要求需自定义
      url: {
        type: String,
        default: '',
        required: false,
      },
    },
    setup(props, { emit }) {
      const douyintime = ref(null);
      const xiaohongshutime = ref(null);
      const taobaotime = ref(null);
      const { createMessage } = useMessage();

      onMounted(() => {
        // 初始化时间
        douyintime.value = props.row.douyintime;
        xiaohongshutime.value = props.row.xiaohongshutime;
        taobaotime.value = props.row.taobaotime;
      });

      /**
       * 自定义的表单页面 弹窗确定按钮触发函数名必须写：handleSubmit
       */
      function handleSubmit() {
        let params = Object.assign({}, props.row, { douyintime: douyintime.value,
          xiaohongshutime: xiaohongshutime.value,
          taobaotime: taobaotime.value,
        });
        defHttp.put({ url: props.url, params }, { isTransformResponse: false }).then((res) => {
          if (res.success) {
            // 提交完毕 关闭弹窗 调用事件：emit('close')
            emit('close');
          } else {
            createMessage.warning(res.message);
          }
        });
      }
      return {
        douyintime,
        xiaohongshutime,
        taobaotime,
        handleSubmit,
      };
    },
  };
</script>
